﻿@model CRM.Op.Common.ResultData<CRM.Infrastructure.Dto.MakeCallXRHLDto>
@{
    ViewBag.Title = "北京鑫锐互联科技发展有限责任公司-外呼服务";
    Layout = "~/Views/Shared/_layer.cshtml";
}
<link href="@Url.Content("~/lib/jcinvccbar/ui/css/darkBlue/vccbar.css")" rel="stylesheet">
<div id="errorMsg" class=""></div>
@section scriptsBottom{
    <script src="~/js/crypto-js.min.js"></script>
    <script type="text/javascript">

        var rt = {
            status: @Model.status,
            msg: '@Model.message',
            close:true
        };
        function window_load() {
            if (rt.status == 0)
            {
                //自定义样式
                applicationUILoad(10, 5, 700, 55, 'cgt');
                applicationLoad(10, 10, 1320, 40, showStyleNONE, '', OnAfterVccBarCreate);
                setTimeout(funInitial, 1000);
            }
            else
            {
                document.getElementById("errorMsg").innerHTML = rt.msg;
                document.getElementById("errorMsg").className = 'alert alert-danger';
            }
        }
        function window_unload(e) {
            if (rt.status == 0)
            {
                application.oJVccBar.Disconnect(1);
                application.oJVccBar.UnInitial(0);

            }
        }
        function funInitial() {
            //var serverIP = '47.95.194.64'; //服务器
            //var vccID = '088891'; //集团号
            //var agentID = '1005'; //工号
            //var pwd = "1j#aON"; //密码
            //var sipPort = '5040'; //sip端口
            //var sipPassword = 'LYcs1e@s$8J55fm';

            var serverIP = '@Model.data.CallServerIP'; //服务器
            var vccID = '@Model.data.CompanyCode'; //集团号
            var agentID = '@Model.data.ProviderSeatNumber'; //工号
            var pwd = "@Model.data.ProviderSeatPassword"; //密码
            var sipPort = '@Model.data.CallSipPort'; //sip端口
            var sipPassword = '@Model.data.CallSipPassword';


            application.oJVccBar.SetAttribute("MainIP", serverIP);  //MainIP
            application.oJVccBar.SetAttribute("MainPortID", @Model.data.CallMainPort);  //MainPort
            application.oJVccBar.SetAttribute("BackIP", serverIP);  //BackIP
            application.oJVccBar.SetAttribute("BackPortID", @Model.data.CallMainPort);  //BackPort
            application.oJVccBar.SetAttribute("MonitorIP", serverIP);  //MonitorIP
            application.oJVccBar.SetAttribute("MonitorPort", 4502);  //MainPort
            application.oJVccBar.SetAttribute("SipServerIP", serverIP);
            application.oJVccBar.SetAttribute("SipDomain", serverIP);
            application.oJVccBar.SetAttribute("SipServerPort", parseInt(sipPort));
            application.oJVccBar.SetAttribute("SipProtocol", "UDP");
            application.oJVccBar.SetAttribute("PhonType", 1);  //0:内置坐席卡；1：内置Sip；2：外置其他终端 3：远程sip电话; 4：软交换前传号码; 5：yealink话机 6：agora
            application.oJVccBar.SetAttribute("AgentType", 1);
            application.oJVccBar.SetAttribute("SelfPrompt", 0);
            application.oJVccBar.SetAttribute("MediaFlag", vccID);
            application.oJVccBar.SetAttribute("AppType", 2);
            application.oJVccBar.SetAttribute("PassWord", pwd);  //坐席密码
            application.oJVccBar.SetAttribute("AgentID",  "000010" + vccID +agentID);
            application.oJVccBar.SetAttribute("Dn", "000002" + vccID + agentID);
            application.oJVccBar.SetAttribute("SipPassWord", sipPassword);
            application.oJVccBar.SetAttribute("WeChatServer", serverIP + ":8000");
            application.oJVccBar.SetAttribute("IsAllTimeRecord", "1"); //1:全程录音 0:不全程录音
            application.oJVccBar.SetAttribute("MinotorVersion", "4.0");
            application.oJVccBar.Initial();
        }
        function OnAfterVccBarCreate() {
            application.oJVccBar.OnReportBtnStatus = onMyReportBtnStatus;
            application.oJVccBar.OnInitalSuccess = onMyOnInitalSuccess;
            application.oJVccBar.OnAgentBusyReason = onMyOnAgentBusyReason;
            application.oJVccBar.OnCallRing = onMyOnCallRing;
            application.oJVccBar.AnswerCall = onMyOnAnswerCall;
            application.oJVccBar.OnCallEnd = onMyOnCallEnd;
            application.oJBarDisplayer = appVccBar;
        }
        function onMyReportBtnStatus(btnIDS) {
            if (application.oVccBarAssist.oBarBtnControl != null) {
                application.oVccBarAssist.oBarBtnControl.UpdateUI(btnIDS);
            }
            if (application.oVccBarAssist.oBarAgentStatus != null) {
                application.oVccBarAssist.oBarAgentStatus.SetAgentStatus(application.oJVccBar.GetAgentStatus());
            }

            if (application.oJBarDisplayer != null) {
                application.oJBarDisplayer.ChangeBtnStatus(btnIDS);
                application.oJBarDisplayer.SetAgentStatus(application.oJVccBar.GetAgentStatus());
            }
        }
        function onMyOnInitalSuccess() {
            if (application.oVccBarAssist.oBarAgentStatus != null) {
                application.oVccBarAssist.oBarAgentStatus.SetSubBusyStatus(application.oJVccBar.GetBusySubStatus());
            }
            if (application.oJBarDisplayer != null) {
                application.oJBarDisplayer.SetSubBusyStatus(application.oJVccBar.GetBusySubStatus());
                application.oJBarDisplayer.SetSubBusySelectedItem(application.oJVccBar.GetAgentSubBusyStatus());
            }
            application.oJVccBar.MakeCall(BMCW.desDecrypt('@Model.data.UserMobile'), 2, '', '', '');
            
        }
        function onMyOnAgentBusyReason(type, des) {
            if (application.oJBarDisplayer != null) {
                application.oJBarDisplayer.SetSubBusySelectedItem(application.oJVccBar.GetAgentSubBusyStatus());
            }
        }
        function onMyOnCallRing(CallingNo, CalledNo, OrgCalledNo, CallData, SerialID, ServiceDirect, CallID, UserParam, TaskID, UserDn, AgentDn, AreaCode, fileName, networkInfo, queueTime, opAgentID, ringTime, projectID, serverName) {
            if (application.oJBarDisplayer != null) {
                application.oJBarDisplayer.SetRingFlag(1);
            }

            BMCW.ajax({
                url: '@Url.Action("SyncCallRing", "Clue")',
                type:"POST",
                data: {
                    CallingNo:CallingNo,
                    CalledNo:CalledNo,
                    OrgCalledNo:OrgCalledNo,
                    CallData:CallData,
                    SerialID:SerialID,
                    ServiceDirect:ServiceDirect,
                    CallID:CallID,
                    UserParam:UserParam,
                    TaskID:TaskID,
                    UserDn:UserDn,
                    AgentDn:AgentDn,
                    AreaCode:AreaCode,
                    FileName:fileName,
                    NetworkInfo:networkInfo,
                    QueueTime:queueTime,
                    OpAgentID:opAgentID,
                    RingTime:ringTime,
                    ProjectID:projectID,
                    ServerName: serverName,
                    ClueID:@Model.data.ClueID,
                    SubID:'@Model.data.SubID',
                    CompanyID:@Model.data.CompanyID
                }
            });
        }
        function onMyOnAnswerCall(UserNo, AnswerTime, SerialID, ServiceDirect, CallID, UserParam, TaskID) {
            if (application.oJBarDisplayer != null) {
                application.oJBarDisplayer.SetRingFlag(0);
            }
            rt.close = false;
            BMCW.ajax({
                url: '@Url.Action("SyncAnswserCall", "Clue")',
                type:"POST",
                data: {
                    ClueID:@Model.data.ClueID,
                    CompanyID:@Model.data.CompanyID,
                    SubID:'@Model.data.SubID',
                    UserNo:UserNo,
                    AnswerTime:AnswerTime,
                    SerialID:SerialID,
                    ServiceDirect:ServiceDirect,
                    CallID:CallID,
                    UserParam:UserParam,
                    TaskID:TaskID
                }
            });
        }
        function onMyOnCallEnd(CallID, SerialID, ServiceDirect, UserNo, BgnTime, EndTime, AgentAlertTime, UserAlertTime, FileName, Directory, DisconnectType, UserParam, TaskID, ServerName, NetworkInfo) {
            if (application.oJBarDisplayer != null) {
                application.oJBarDisplayer.SetRingFlag(0);
            }
            BMCW.ajax({
                url: '@Url.Action("SyncCallEnd", "Clue")',
                type:"POST",
                data: {
                    CallID:CallID,
                    SerialID:SerialID,
                    ClueID:@Model.data.ClueID,
                    SubID:'@Model.data.SubID',
                    CompanyID:@Model.data.CompanyID,
                    ServiceDirect:ServiceDirect,
                    UserNo:UserNo,
                    BgnTime:BgnTime,
                    EndTime:EndTime,
                    AgentAlertTime:AgentAlertTime,
                    UserAlertTime:UserAlertTime,
                    FileName:FileName,
                    Directory:Directory,
                    DisconnectType:DisconnectType,
                    UserParam:UserParam,
                    TaskID:TaskID,
                    ServerName:ServerName,
                    NetworkInfo: NetworkInfo
                },
                success:function(){
                    rt.close=true;
                }
            });
        }
    </script>
}
